<?php
require_once 'FileInterface.php';
/**
 * Abstract class for files(folders are also considered a special file type by the OS)
 * Contains some basic methods common to both files & folders and implements the FileInterface
 * @author Sukhbir Singh Grewal
 *
 */
abstract class FileAbstract implements FileInterface
{
	protected $filename;
	protected $location;
	
	//initialize
	public function __construct($absolutePath, $filename)
	{
		if(empty($absolutePath) || empty($filename))
			throw new ExceptionHandler('Invalid arguments to create folder object');				
		$this->filename = $filename;
		$this->location = $absolutePath;
	}
	
	public function isDir()
	{		
		if(is_dir($this->location))
			return true;
		else
			return false;
	}
	
	public function getInfo()
	{			
		if($this->isDir())		
			$filesize = null;
		else
			$filesize = filesize($this->location);
		return array('name' => $this->filename,
						'absolutePath' => $this->location,
						'isDir' => $this->isDir(),
						'filesize' => $filesize,						
					);
	}
	
	public function canRead()
	{
		if(!is_readable($this->location))
			return false;
		else
			return true;
	}
	
	public function canWrite()
	{
		if(!is_writable($this->location))
			return false;
		else
			return true;
	}
}


?>